/** @jsxImportSource @emotion/react */
import * as React from "react";
import {
    Text, InputLine, Table, TableHead, TableRow, CCell, TableBody, LineColumn,
} from "customize-easy-ui-component";
import {
    InspectRecordLayout, InternalItemProps, RepLink, SelectHookfork, useItemInputControl,
} from "../../common/base";
import {useMeasureInpFilter} from "../../common/hooks";
import {Each_ZdSetting, useTableEditor} from "../../hook/useRepTableEditor";

const tail间隙 = <Text css={{"@media print": {fontSize: '0.75rem'}}}>
    注：1、对于不合格的值才需测量和记录，未测量或无需测量的，仅填检验结果栏。<br/>
    2、以设计文件作为检验结果判定依据时，设计要求值填在备注栏内。
</Text>;
const config间隙表=[['层站','n',66],['门地厢地坎隙','k',60],['层门净高','H',60,],['门扇间间隙','j',60],['门立柱隙','z',60],['门扇地坎间隙','s',60],
           ['扇施力间隙','p',60],['门锁啮合深','l',60]] as Each_ZdSetting[];
export const itemA间隙=['间隙表','门净高r','门扇隙r','施力隙r','门地间r','锁啮深r'];
export const DoorGap=
    React.forwardRef(({ children, show ,alone=true,refWidth,label}:InternalItemProps,  ref
    ) => {
        const [getInpFilter]=useMeasureInpFilter(null, itemA间隙,);
        const {inp, setInp} = useItemInputControl({ ref });
        const headview=<Text variant="h5">
            参照上面样表的第6行的标注的各列的简化后的列名来进行录入,结果2行拆出单独录入。单位：mm
        </Text>;
        const [render间隙表]=useTableEditor({inp, setInp,  headview,
            config: config间隙表, table:'间隙表', column:8});
        return (
            <InspectRecordLayout inp={inp} setInp={setInp} getInpFilter={getInpFilter} show={show}
                                 alone={alone} label={label!}>
                <Text variant="h5">
                    {label} 单位：mm
                </Text>
                样表格式如下：
                <Table css={{borderCollapse: 'collapse'}} tight miniw={800}>
                    <TableBody>
                    <TableRow>
                        <CCell rowSpan={2}>项目编号</CCell><CCell colSpan={7}>C5</CCell>
                    </TableRow>
                    <TableRow>
                        <CCell>（1）</CCell><CCell>（1）</CCell><CCell colSpan={3}>（1）</CCell><CCell>（1）</CCell><CCell>（4）</CCell>
                    </TableRow>
                    <TableRow>
                        <CCell>检验内容</CCell><CCell>层门地坎与货厢地坎的间隙</CCell><CCell>层门净高度</CCell><CCell>层门门扇间间隙</CCell><CCell>层门扇与立柱间隙</CCell>
                        <CCell>层门扇与地坎间隙</CCell><CCell>层门扇间施力间隙</CCell><CCell>门锁啮合深度</CCell>
                    </TableRow>
                    <TableRow>
                        <CCell rowSpan={2}>判断标准</CCell><CCell rowSpan={2}>0≤x≤35</CCell><CCell rowSpan={2}>x≥1800</CCell><CCell rowSpan={2} colSpan={3}>x≤10</CCell>
                        <CCell>旁开门： x≤30</CCell><CCell rowSpan={2}>x≥7</CCell>
                    </TableRow>
                    <TableRow>
                        <CCell>中分门总和： x≤45</CCell>
                    </TableRow>
                    <TableRow>
                        <CCell>层站</CCell><CCell>门地厢地坎隙</CCell><CCell>层门净高</CCell><CCell>门扇间间隙</CCell><CCell>门立柱隙</CCell><CCell>门扇地坎间隙</CCell><CCell>扇施力间隙</CCell><CCell>门锁啮合深</CCell>
                    </TableRow>
                    <TableRow>
                        <CCell>检验结果</CCell><CCell></CCell><CCell></CCell><CCell colSpan={3}></CCell><CCell></CCell><CCell></CCell>
                    </TableRow>
                </TableBody></Table>
                {render间隙表}
                <hr/>
                上表最后一行结果行的录入拆出来：
                <LineColumn column={6}>
                    <InputLine label={`5（1）层门地坎与货厢地坎的间隙-检验结果`}>
                        <SelectHookfork value={ inp?.门地间r ||''}
                                        onChange={e => setInp({ ...inp, 门地间r: e.currentTarget.value||undefined}) }/>
                    </InputLine>
                    <InputLine label={`5（1）层门净高度-检验结果`}>
                        <SelectHookfork value={ inp?.门净高r ||''}
                                        onChange={e => setInp({ ...inp, 门净高r: e.currentTarget.value||undefined}) }/>
                    </InputLine>
                    <InputLine label={`5（1）门扇间间隙，门扇立柱隙，门扇地坎间隙-检验结果`}>
                        <SelectHookfork value={ inp?.门扇隙r ||''}
                                        onChange={e => setInp({ ...inp, 门扇隙r: e.currentTarget.value||undefined}) }/>
                    </InputLine>
                    <InputLine label={`5（1）层门扇间施力间隙-检验结果`}>
                        <SelectHookfork value={ inp?.施力隙r ||''}
                                        onChange={e => setInp({ ...inp, 施力隙r: e.currentTarget.value||undefined}) }/>
                    </InputLine>
                    <InputLine label={`5（4）门锁啮合深度-检验结果`}>
                        <SelectHookfork value={ inp?.锁啮深r ||''}
                                        onChange={e => setInp({ ...inp, 锁啮深r: e.currentTarget.value||undefined}) }/>
                    </InputLine>
                </LineColumn>
                {children? children : tail间隙}
            </InspectRecordLayout>
        );
} );

export const DoorGapVw= ({children, orc, rep,label } : { orc: any, rep: any,label:any, children?: any}
) => {
    const gcRows=(orc?.间隙表?.length??1);
    return <>
        <div css={{"@media print": {paddingBottom: '9.5rem', pageBreakInside: 'avoid'}}}>
            <Text variant="h4" css={{marginTop: '1rem',
            }}>{label}</Text>
            <div css={{textAlign: 'right'}}>单位：mm</div>
        </div>
        <Table id='Gap' fixed={ ["4.2%", "5%", "3%","14%","13%","11%","12%","%","15%","11%"] }
                  css={{borderCollapse: 'collapse', "@media print": {marginTop: '-9.5rem'}}} tight  miniw={800}>
          <TableHead>
              <TableRow>
                  <CCell rowSpan={2} colSpan={3}>项目编号</CCell><CCell colSpan={7}>C5</CCell>
              </TableRow>
              <TableRow>
                  <CCell>（1）</CCell><CCell>（1）</CCell><CCell colSpan={3}>（1）</CCell><CCell>（1）</CCell><CCell>（4）</CCell>
              </TableRow>
              <TableRow>
                  <CCell colSpan={3}>检验内容</CCell><CCell>层门地坎与货厢地坎的间隙</CCell><CCell>层门净高度</CCell><CCell>层门门扇间间隙</CCell><CCell>层门扇与立柱间隙</CCell>
                  <CCell>层门扇与地坎间隙</CCell><CCell>层门扇间施力间隙</CCell><CCell>门锁啮合深度</CCell>
              </TableRow>
          </TableHead>
         <TableBody>
           <RepLink ori rep={rep} tag={'Gap'}>
               <TableRow>
                   <CCell rowSpan={2} colSpan={3}>判断标准</CCell><CCell rowSpan={2}>0≤x≤35</CCell><CCell rowSpan={2}>x≥1800</CCell><CCell rowSpan={2} colSpan={3}>x≤10</CCell>
                   <CCell>旁开门： x≤30</CCell><CCell rowSpan={2}>x≥7</CCell>
               </TableRow>
               <TableRow>
                   <CCell>中分门总和： x≤45</CCell>
               </TableRow>
            { (orc?.间隙表??[{}]).map((o: any, i: number) => {
                 return <TableRow key={i}>
                     {0===i && <CCell  split  rowSpan={gcRows}>观测数据</CCell>}
                     <CCell>{o?.n??'／'}</CCell>
                     <CCell><Text css={{fontSize: '0.7rem'}}>层</Text></CCell>
                     <CCell>{o?.k??'／'}</CCell>
                     <CCell>{o?.H??'／'}</CCell>
                     <CCell>{o?.j??'／'}</CCell>
                     <CCell>{o?.z??'／'}</CCell>
                     <CCell>{o?.s??'／'}</CCell>
                     <CCell>{o?.p??'／'}</CCell>
                     <CCell>{o?.l??'／'}</CCell>
                 </TableRow>
            })}
            <TableRow>
               <CCell colSpan={3}>检验结果</CCell><CCell>{orc?.门地间r??'／'}</CCell><CCell>{orc?.门净高r??'／'}</CCell><CCell colSpan={3}>{orc?.门扇隙r??'／'}</CCell>
                <CCell>{orc?.施力隙r??'／'}</CCell><CCell>{orc?.锁啮深r??'／'}</CCell>
            </TableRow>
          </RepLink>
         </TableBody>
        </Table>
        {children? children : tail间隙}
    </>;
};
